/**
 * 作者：陈文斌 on 2019/1/7.
 * 邮箱：chen_wennbin@163.com
 * 版本：v1.0
 */

import 'package:flutter/material.dart';
import 'package:crm/constant/constant.dart';

class ListTileNormal extends StatelessWidget {
  /// 行高
  final double height;

  /// 标题前面小部件
  final Widget leading;

  /// 标题
  final Widget title;

  /// 标题后面小部件
  final Widget trailing;

  /// 隐藏分割线
  final bool dividerVisible;

  /// 隐藏箭头
  final bool arrowVisible;

  /// 内边距
  final EdgeInsetsGeometry contentPadding;

  /// leading右边距
  final double leadingRightPadding;

  /// 点击回调
  final GestureTapCallback onTap;

  final Color backgroundColor;

  ListTileNormal({
    Key key,
    this.height = 44,
    this.leading,
    this.title,
    this.trailing,
    this.contentPadding,
    this.onTap,
    this.leadingRightPadding = 15,
    this.backgroundColor = Colors.white,
    this.dividerVisible = false,
    this.arrowVisible = false,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final _leadingVisible = leading == null;

    /// 标题前面的小部件
    Widget _leading = Offstage(
      offstage: _leadingVisible,
      child: Row(
        children: <Widget>[
          Container(
            width: 20,
            height: 20,
            child: leading,
          ),
          Padding(padding: EdgeInsets.only(right: leadingRightPadding)),
        ],
      ),
    );

    /// 标题
    Widget _title = Expanded(
      child: title ?? Container(),
    );

    /// 标题后面的小部件
    Widget _trailing = trailing != null ? Container(
      constraints: BoxConstraints(
        maxWidth: AppScreen.setWidth(375 ~/ 5 * 3),
      ),
      child: trailing,
    ): Container();

    /// 箭头
    Widget _arrow = Offstage(
      offstage: arrowVisible,
      child: Container(
        width: 12,
        height: 12,
        child: Image.asset(
          'images/ic_arrow_left.png',
          fit: BoxFit.fill,
        ),
      ),
    );

    /// 分割线
    Widget _divider = Offstage(
      offstage: dividerVisible,
      child: Container(
        height: 1,
        margin: EdgeInsets.only(left: 16),
        color: AppColors.LineColor,
      ),
    );

    return Material(
      color: backgroundColor,
      child: InkWell(
        onTap: onTap,
        child: Column(
          children: <Widget>[
            Container(
              width: AppScreen.setWidth(375),
              constraints: BoxConstraints(minHeight: height - 1),
              padding: contentPadding ??
                  EdgeInsets.fromLTRB(
                    16,
                    11.5,
                    16,
                    11.5,
                  ),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  Expanded(
                    child: Row(
                      children: <Widget>[
                        _leading,
                        _title,
                      ],
                    ),
                  ),
                  _trailing,
                  _arrow,
                ],
              ),
            ),
            _divider,
          ],
        ),
      ),
    );
  }
}
